//通知公告设置

import React, { useState, useEffect } from 'react';
import { Button, Input, Space, Tag, message } from 'antd';
import UploadFile from '../../Compon/UploadFile';
import Gooutfile from '../../Compon/file/Gooutfile.jsx';
import moment from 'moment';
import {
  get_tongzhigonggao_list,
  delete_tongzhigonggao_list,
} from '../../utils/api';
import Toptitle from '../../Compon/Toptitle';
import Tbale from '../../components/ContentManagement/content_components/Tbale';
export default function NoticeAndAnnouncement() {
  const [data, setData] = useState([]);
  const a = async () => {
    const res = await get_tongzhigonggao_list();
    // console.log(res);
    setData(res.data.data);
  };
  useEffect(() => {
    a();
  }, []);
  const columns = [
    {
      title: '序号',
      dataIndex: '_id',
      key: '_id',
      render: (text, record, index) => index + 1,
    },
    {
      title: 'ID',
      dataIndex: '_id',
      key: '_id_',
    },
    {
      title: '标题',
      dataIndex: 'tongzhigonggao_title',
      key: 'tongzhigonggao_title',
    },
    {
      title: '所属页面',
      dataIndex: 'tongzhigonggao_suoshuyemian',
      key: 'tongzhigonggao_suoshuyemian',
    },
    {
      title: '发布时间',
      dataIndex: 'tongzhigonggao_time',
      key: 'tongzhigonggao_time',
      render: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
    },
    {
      title: '状态',
      dataIndex: 'tongzhigonggao_state',
      key: 'tongzhigonggao_state',
      render: (text) => (
        <Tag color={text === 1 ? 'green' : 'red'}>
          {text === 1 ? '启用' : '禁用'}
        </Tag>
      ),
    },
    {
      title: '操作',
      dataIndex: '_id',
      key: '_id',
      render: (text, record) => (
        <Space size="middle">
          <Button
            type="primary"
            danger
            onClick={async () => {
              if (confirm('确定删除吗')) {
                await delete_tongzhigonggao_list({ text: record._id });
                a();
                message.success('删除成功');
              } else {
                message.error('取消删除');
              }
            }}
          >
            删除
          </Button>
        </Space>
      ),
    },
  ];
  return (
    <div>
      <Toptitle title={'通知公告设置'}></Toptitle>
      <Tbale data={data} colums={columns}></Tbale>
      <div style={{ display: 'flex' }}>
        <UploadFile
          name={'导入'}
          // url="http://localhost:3000/CustomerService/index/uploadFile"
        ></UploadFile>

        <Gooutfile data={data}></Gooutfile>
      </div>
    </div>
  );
}
